﻿using Action = Styx.TreeSharp.Action;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace Spriest
{
    public partial class Classname : CombatRoutine
    {
        public bool usemindflay()
        {
            if (gotTarget
                && !insanitycheck
                && dotOnTarget
                && SpellManager.HasSpell(MindFlay)
                && !useAoe)
            {
                return true;
            }
            return false;
        }
        public bool usemindblast()
        {
            if (gotTarget
                && !insanitycheck
                && SpellManager.HasSpell(MindBlast)
                && !spellOnCooldown(MindBlast)
                && !useAoe)
            {
                return true;
            }
            return false;
        }
        public bool usevampirictouch()
        {
            if (gotTarget
                && !insanitycheck
                && useDoTs
                && SpellManager.HasSpell(VampiricTouch)
                && !spellOnCooldown(VampiricTouch)
                && (!debuffExists(VampiricTouch, Me.CurrentTarget)
                || debuffTimeLeft(VampiricTouch, Me.CurrentTarget) < 4000)
                && !useAoe
                && LastSpellID != VampiricTouch)
            {
                return true;
            }
            return false;
        }
        public bool useshadowwordpain()
        {
            if (gotTarget
                && !insanitycheck
                && useDoTs
                && SpellManager.HasSpell(ShadowWordPain)
                && !spellOnCooldown(ShadowWordPain)
                && (!debuffExists(ShadowWordPain, Me.CurrentTarget)
                || debuffTimeLeft(ShadowWordPain, Me.CurrentTarget) < 4000)
                && !useAoe
                && LastSpellID != ShadowWordPain)
            {
                return true;
            }
            return false;
        }
        public bool usedevouringplague()
        {
            if (gotTarget
                && SpellManager.HasSpell(DevouringPlague)
                && IsBoss
                && Me.GetCurrentPower(WoWPowerType.ShadowOrbs) >= 3
                && !useAoe)
            {
                return true;
            }
            if (gotTarget
                && SpellManager.HasSpell(DevouringPlague)
                && !IsBoss
                && Me.GetCurrentPower(WoWPowerType.ShadowOrbs) >= SpriestSettings.myPrefs.shadoworbs
                && Me.CurrentTarget.HealthPercent > 20
                && !useAoe)
            {
                return true;
            }
            return false;
        }
        public bool useinsanity()
        {
            if (gotTarget
                && insanitycheck
                && SpellManager.HasSpell(MindFlay)
                && !useAoe)
            {
                return true;
            }
            return false;
        }
        public bool usedivineinsight()
        {
            if (gotTarget
                && !insanitycheck
                && dotOnTarget
                && SpellManager.HasSpell(MindBlast)
                && buffExists(DivineInsight, Me)
                && !useAoe)
            {
                return true;
            }
            return false;
        }
        public bool usemindsear()
        {
            if (gotTarget
                && SpellManager.HasSpell(MindSear)
                && SpriestSettings.myPrefs.usemindsear == 1
                && (Me.GroupInfo.IsInParty
                || Me.GroupInfo.IsInRaid
                || Me.IsInInstance)
                && useAoe)
            {
                return true;
            }
            if (gotTarget
                && SpellManager.HasSpell(MindSear)
                && SpriestSettings.myPrefs.usemindsear == 2
                && useAoe)
            {
                return true;
            }
            return false;
        }
        public bool usecascade()
        {
            if (gotTarget
                && SpellManager.HasSpell(Cascade)
                && !spellOnCooldown(Cascade)
                && useAoe)
            {
                return true;
            }
            if (gotTarget
                && !insanitycheck
                && SpellManager.HasSpell(Cascade)
                && !spellOnCooldown(Cascade)
                && SpriestSettings.myPrefs.cascade == 1
                && SpriestSettings.myPrefs.usecascade == 1
                && IsBoss)
            {
                return true;
            }
            if (gotTarget
                && !insanitycheck
                && SpellManager.HasSpell(Cascade)
                && !spellOnCooldown(Cascade)
                && SpriestSettings.myPrefs.cascade == 1
                && SpriestSettings.myPrefs.usecascade == 2)
            {
                return true;
            }
            return false;
        }
        public bool useDivineStar()
        {
            if(gotTarget
                && SpellManager.HasSpell("Divine Star")
                && !spellOnCooldown(DivineStar)
                && SpriestSettings.myPrefs.divinestar == 1
                && (SpriestSettings.myPrefs.usedivinestar == 1
                || (SpriestSettings.myPrefs.usedivinestar == 2 && IsBoss)))
            {
                return true;
            }
            return false;
        }
        public bool useHalo()
        {
            if (gotTarget
                && SpellManager.HasSpell("Halo")
                && !spellOnCooldown(DivineStar)
                && SpriestSettings.myPrefs.halo == 1
                && (SpriestSettings.myPrefs.usehalo == 1
                || (SpriestSettings.myPrefs.usehalo == 2 && IsBoss)))
            {
                return true;
            }
            return false;
        }
        public bool usepowerwordforitude()
        {
            if (!buffExists(PowerWordFortitude, Me)
                && !Me.HasAura("Dark Intent")
                && LastSpellID != PowerWordFortitude)
            {
                return true;
            }
            return false;
        }
        public bool useinnerfire()
        {
            if (!buffExists(InnerFire, Me)
                && LastSpellID != InnerFire)
            {
                return true;
            }
            return false;
        }
        public bool useshadowform()
        {
            if (!buffExists(ShadowForm, Me)
                && Me.HealthPercent > SpriestSettings.myPrefs.FlashHealPercent
                && LastSpellID != ShadowForm)
            {
                return true;
            }
            return false;
        }
        public bool usepowerinfusion()
        {
            if (gotTarget
                && SpellManager.HasSpell(PowerInfusion)
                && !spellOnCooldown(PowerInfusion)
                && SpriestSettings.myPrefs.powerinfusion == 1
                && SpriestSettings.myPrefs.usepowerinfusion == 1
                && !useAoe
                && IsBoss)
            {
                return true;
            }
            if (gotTarget
                && SpellManager.HasSpell(PowerInfusion)
                && !spellOnCooldown(PowerInfusion)
                && SpriestSettings.myPrefs.powerinfusion == 1
                && SpriestSettings.myPrefs.usepowerinfusion == 3
                && !useAoe)
            {
                return true;
            }
            return false;
        }
        public bool usemindspike()
        {
            if (gotTarget
                && SpellManager.HasSpell(FromDarknessComesLight)
                && SpriestSettings.myPrefs.DarknessLight == 1
                && buffExists("Surge of Darkness", Me)
                && !useAoe)
            {
                return true;
            }
            return false;
        }
        public bool useshadowworddeath()
        {
            if (gotTarget
                && SpellManager.HasSpell(ShadowWordDeath)
                && Me.CurrentTarget.HealthPercent <= 20
                && !spellOnCooldown(ShadowWordDeath)
                && !useAoe)
            {
                return true;
            }
            return false;
        }
        public bool usesmite()
        {
            if (gotTarget
                && Me.Level < 10
                && SpellManager.HasSpell("Smite"))
            {
                return true;
            }
            return false;
        }
        public bool uselifeblood()
        {
            if (gotTarget
                && SpellManager.HasSpell(Lifeblood)
                && !spellOnCooldown(Lifeblood)
                && SpriestSettings.myPrefs.lifebloodYorN == 1
                && SpriestSettings.myPrefs.uselifeblood == 1
                && !useAoe
                && IsBoss)
            {
                return true;
            }
            if (gotTarget
                && SpellManager.HasSpell(Lifeblood)
                && !spellOnCooldown(Lifeblood)
                && SpriestSettings.myPrefs.lifebloodYorN == 1
                && SpriestSettings.myPrefs.uselifeblood == 2
                && !useAoe)
            {
                return true;
            }
            return false;
        }
        public bool usemindbender()
        {
            if (Me.HealthPercent <= SpriestSettings.myPrefs.beestjepercent
                && !spellOnCooldown(MindBinder))
            {
                return true;
            }
            if (gotTarget
                && SpellManager.HasSpell(MindBinder)
                && !spellOnCooldown(MindBinder)
                && SpriestSettings.myPrefs.mindbender == 1
                && SpriestSettings.myPrefs.beestje == 1
                && Me.CurrentTarget.HealthPercent > 10
                && !useAoe
                && IsBoss)
            {
                return true;
            }
            if (gotTarget
                && SpellManager.HasSpell(MindBinder)
                && !spellOnCooldown(MindBinder)
                && SpriestSettings.myPrefs.mindbender == 1
                && SpriestSettings.myPrefs.beestje == 2
                && Me.CurrentTarget.HealthPercent > 20
                && !useAoe)
            {
                return true;
            }
            return false;
        }
        public bool useshadowfiend()
        {
            if (Me.HealthPercent <= SpriestSettings.myPrefs.beestjepercent
                && !spellOnCooldown(ShadowFiend))
            {
                return true;
            }
            if (gotTarget
                && SpriestSettings.myPrefs.mindbender == 0
                && SpellManager.HasSpell(ShadowFiend)
                && !spellOnCooldown(ShadowFiend)
                && SpriestSettings.myPrefs.beestje == 1
                && Me.CurrentTarget.HealthPercent > 10
                && !useAoe
                && IsBoss)
            {
                return true;
            }
            if (gotTarget
                && SpriestSettings.myPrefs.mindbender == 0
                && SpellManager.HasSpell(ShadowFiend)
                && !spellOnCooldown(ShadowFiend)
                && SpriestSettings.myPrefs.beestje == 2
                && Me.CurrentTarget.HealthPercent > 20
                && !useAoe)
            {
                return true;
            }
            return false;
        }
        public bool usepsychicscream()
        {
            if (gotTarget
                && SpriestSettings.myPrefs.psyscream == 1
                && nearbyTargets(Me.CurrentTarget.Location, 3).Count() > SpriestSettings.myPrefs.psyscreamadds
                && SpellManager.HasSpell(PsychicScream)
                && !spellOnCooldown(PsychicScream)
                && !Me.CurrentTarget.IsUndead
                && !debuffExists(VoidTendrils, Me.CurrentTarget))
            {
                return true;
            }
            return false;
        }
        public bool usevoidtendrils()
        {
            if (gotTarget
                && SpriestSettings.myPrefs.voidtendrils == 1
                && nearbyTargets(Me.CurrentTarget.Location, 3).Count() >= SpriestSettings.myPrefs.tendriladds
                && SpellManager.HasSpell(VoidTendrils)
                && !spellOnCooldown(VoidTendrils)
                && LastSpellID != PsychicScream)
            {
                return true;
            }
            return false;
        }
        public bool usesilence()
        {
            if (gotTarget
                && SpriestSettings.myPrefs.silence == 1
                && SpellManager.HasSpell(Silence)
                && !spellOnCooldown(Silence)
                && (Me.CurrentTarget.IsCasting
                && Me.CanInterruptCurrentSpellCast))
            {
                return true;
            }
            return false;
        }
        public bool usedispersion()
        {
            if (SpellManager.HasSpell(Dispersion)
                && !spellOnCooldown(Dispersion)
                && (Me.ManaPercent <= SpriestSettings.myPrefs.dispersionmana
                || Me.HealthPercent <= SpriestSettings.myPrefs.dispersionhealth))
            {
                return true;
            }
            return false;
        }
        public bool usedesperateprayer()
        {
            if (SpriestSettings.myPrefs.DesperatePrayerYorN == 1
                && SpellManager.HasSpell(DesperatePrayer)
                && !spellOnCooldown(DesperatePrayer)
                && Me.HealthPercent <= SpriestSettings.myPrefs.DesperatePrayerPercent)
            {
                return true;
            }
            return false;
        }
        public bool usepowerwordshield()
        {
            if (SpellManager.HasSpell(PowerWordShield)
                && !spellOnCooldown(PowerWordShield)
                && !buffExists(PowerWordShield, Me)
                && Me.HealthPercent <= SpriestSettings.myPrefs.PowerWordShieldPercent)
            {
                return true;
            }
            return false;
        }
        public bool useflashheal()
        {
            if (SpellManager.HasSpell(FlashHeal)
                && Me.HealthPercent <= SpriestSettings.myPrefs.FlashHealPercent)
            {
                return true;
            }
            return false;
        }
        public bool userenew()
        {
            if (SpellManager.HasSpell(Renew)
                && !buffExists(Renew, Me)
                && Me.HealthPercent <= SpriestSettings.myPrefs.RenewPercent)
            {
                return true;
            }
            return false;
        }
        public bool usenaruu()
        {
            if (gotTarget
                && SpellManager.HasSpell(GiftOfTheNaruu)
                && !spellOnCooldown(GiftOfTheNaruu)
                && Me.HealthPercent <= SpriestSettings.myPrefs.naruupercent)
            {
                return true;
            }
            return false;
        }

        public bool usevampiricembrace()
        {
            if (gotTarget
                && SpellManager.HasSpell(VampiricEmbrace)
                && !spellOnCooldown(VampiricEmbrace)
                && Me.HealthPercent <= SpriestSettings.myPrefs.VampiricEmbracePercent)
            {
                return true;
            }
            return false;
        }
        public bool usefearward()
        {
            if (SpellManager.HasSpell(FearWard)
                && SpriestSettings.myPrefs.FearWard
                && !buffExists(FearWard, Me)
                && !spellOnCooldown(FearWard))
            {
                return true;
            }
            return false;
        }
        public bool useshackleundead()
        {
            if (gotTarget
                && SpellManager.HasSpell(ShackleUndead)
                && Me.CurrentTarget.IsUndead
                && Me.CurrentTarget.IsPlayer
                && !debuffExists(ShackleUndead, Me.CurrentTarget)
                && !spellOnCooldown(ShackleUndead))
            {
                return true;
            }

            return false;
        }
        #region checks
        public bool insanitycheck
        {
            get
            {
                if (SpriestSettings.myPrefs.insanity == 1
                    && debuffExists(DevouringPlague, Me.CurrentTarget))
                {
                    return true;
                }
                return false;
            }
        }
        public bool dotOnTarget
        {
            get
            {
                if (gotTarget
                    && SpellManager.HasSpell(ShadowWordPain)
                    && !SpellManager.HasSpell(VampiricTouch)
                    && debuffExists(ShadowWordPain, Me.CurrentTarget))
                {
                    return true;
                }
                if (gotTarget
                    && SpellManager.HasSpell(ShadowWordPain)
                    && SpellManager.HasSpell(VampiricTouch)
                    && debuffExists(ShadowWordPain, Me.CurrentTarget)
                    && debuffExists(VampiricTouch, Me.CurrentTarget))
                {
                    return true;
                }
                return false;
            }
        }
        public bool useDoTs
        {
            get
            {
                if (gotTarget
                    && IsBoss)
                {
                    return true;
                }
                if (gotTarget
                    && Me.CurrentTarget.HealthPercent > 20
                    && !IsBoss
                    || (Me.CurrentTarget.HealthPercent > 0 && !SpellManager.HasSpell(ShadowWordDeath)))
                {
                    return true;
                }
                return false;
            }
        }
        public bool shadoworbs
        {
            get
            {
                if (gotTarget
                    && !IsBoss
                    && Me.GetCurrentPower(WoWPowerType.ShadowOrbs) >= SpriestSettings.myPrefs.shadoworbs
                    && Me.CurrentTarget.HealthPercent > 20)
                {
                    return true;
                }
                if (gotTarget
                    && IsBoss
                    && Me.GetCurrentPower(WoWPowerType.ShadowOrbs) >= 3)
                {
                    return true;
                }
                return false;
            }
        }
        #endregion checks

        #region MultiDot
        public WoWUnit DotTarget()
        {

            WoWUnit needDot =
            (from wowUnit in ObjectManager.GetObjectsOfType<WoWUnit>(true, false)
             where !debuffExists(ShadowWordPain, wowUnit)
             && wowUnit != Me.CurrentTarget
             && (wowUnit.IsTargetingMeOrPet
             || wowUnit.IsTargetingMyPartyMember
             || wowUnit.IsTargetingMyRaidMember)
             orderby wowUnit.DistanceSqr <= 10
             select wowUnit)
            .FirstOrDefault();

            return needDot;
        }
        #endregion MultiDot
    }
}
